

/**
 * 是否开发者模式
 * @returns {boolean}
 */
export const isDev = process.env.VUE_APP_IS_DEV == 'true' ? true : false

/**
 * 获取路由 ? & 的参数对象
 */
export const getQueryStringArgs = () => {
    var qs = (window.location.search.length > 0 ? window.location.search.substring(1) : '')
    var args = {},
        items = qs.length ? qs.split("&") : [],
        item = null,
        name = null,
        value = null,
        i = 0,
        len = items.length;
    for (i = 0; i < len; i++) {
        item = items[i].split("=");
        name = decodeURIComponent(item[0]);
        value = decodeURIComponent(item[1]);
        if (name.length)
            args[name] = value
    }
    return args;
}

/**
 * 获取窗口可视范围的高度
 * @returns {number}
 */
export const clientHeight = () => {
    var clientHeight = 0;
    if (document.body.clientHeight && document.documentElement.clientHeight) {
        var clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
    } else {
        var clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
    }
    return clientHeight;
}

/**
 * 获取文档内容实际高度
 * @returns {number}
 */
export const scrollHeight = () => {
    return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}

/**
 * 获取窗口滚动条高度
 * @returns {number}
 */
export const getScrollTop = () => {
    var scrollTop = 0;
    if (document.documentElement && document.documentElement.scrollTop) {
        scrollTop = document.documentElement.scrollTop;
    } else if (document.body) {
        scrollTop = document.body.scrollTop;
    }
    return scrollTop;
}

export const getUrlParamObj=()=>{
    var obj = {};
    //获取url的参数部分
    var params = window.location.search.substr(1);
    //[^&=]+ 表示不含&或=的连续字符，加上()就是提取对应字符串
    params.replace(/([^&=]+)=([^&=]*)/gi,function(rs,$1,$2){
        obj[$1] = $2;
    });

    return obj;
}

export const getUrlHash =()=>{
    let split =  window.location.href.split('#')
    return split.length>1?split[1]:''
}


export const isNullJSON=(data)=>{
    if (JSON.stringify(data) === '{}') {
        return false // 如果为空,返回false
    }
    return true // 如果不为空，则会执行到这一步，返回true
}

export const getScaleHeight=(selector)=>{
    let _dom = document.querySelector(selector);
    if(!_dom) return;
    let _width = _dom.clientWidth
    let _height = _width * (9 / 16);
    _dom.style.height = _width * (9 / 16) + 'px'
    return _height
}

export const getScaleHeightByRate=(selector)=>{
    let _dom = document.querySelector(selector);
    console.log(selector)
    console.log(_dom)
    if(!_dom) return;
    let _width = _dom.clientWidth
    let _height = _width
    _dom.style.height = _width + 'px'
    console.log(_width)
    console.log(_height)
    return _height
}

//转意符换成普通字符
export const escape2Html= function(str) {
    var arrEntities={'lt':'<','gt':'>','nbsp':' ','amp':'&','quot':'"'};
    return str.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(all,t){return arrEntities[t];});
}
